/*
* @Author: wgt
* @Date:   2018-06-19 10:07:51
* @Last Modified by:   wgt
* @Last Modified time: 2018-06-19 20:47:16
*/
//webpack object
var webpack = require('webpack');

var ExtractTextPlugin = require("extract-text-webpack-plugin");

var HtmlWebpackPlugin = require('html-webpack-plugin');



/********************************************************/
// 环境变量配置，dev / online
var WEBPACK_ENV         = process.env.WEBPACK_ENV || 'dev';

/********************************************************/
var getHtmlConfig = function(name, title){
    return {
        template    : './src/view/' + name + '.html',
        filename    : 'view/' + name + '.html',
        title       : title,
        inject      : true,
        hash        : true,
        chunks      : ['commons', name]
    };
};
/********************************************************/

//globel 配置
config = {
    entry: {
    	"commons" : ["./src/page/commons/commons.js", "webpack-dev-server/client?http://localhost:8088/"],
    	"index" : ["./src/page/index/index.js"],
    	"login" : ["./src/page/login/index.js"],
    	
    },
    output: {
      filename: 'js/[name].bundle.js',
      path: "./dist/",
      publicPath: "/dist"
    },
    externals: {
	    jquery:'window.$'
	},
	module: {
    	loaders: [
      		{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader","css-loader")},
          { test: /\.(gif|png|jpg|woff|svg|eot|ttf)\??.*$/, loader: 'url-loader?limit=100&name=../resource/[name].[ext]' },
          { test: /\.string$/, loader: 'html-loader'}
    	]
  	},
	plugins: [
		new webpack.optimize.CommonsChunkPlugin({
			name : "commons",
			filename : "js/base.js"
		}),
		new ExtractTextPlugin("css/[name].css"),
		new HtmlWebpackPlugin(getHtmlConfig("index","index")),
	]
};

//判断是否为dev环境
if('dev' === WEBPACK_ENV){
    config.entry.commons.push('webpack-dev-server/client?http://localhost:8088/');
}

module.exports = config;
